package JZOffer;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Stack;

// 包含min函数的栈
public class JzOffer30 {
    static class MinStack {
        private Deque<Integer> stack;
        private Deque<Integer> minStack;

        /** initialize your data structure here. */
        public MinStack() {
            stack = new ArrayDeque<>();
            minStack = new ArrayDeque<>();
            minStack.push(Integer.MAX_VALUE);
        }

        public void push(int x) {
            stack.push(x);
            minStack.push(Math.min(minStack.peek(), x));
        }

        public void pop() {
            stack.pop();
            minStack.pop();
        }

        public int top() {
            return stack.peek();
        }

        public int min() {
            return minStack.peek();
        }
    }
}
